package com.atguigu.gmall.publisher.controller;

import com.atguigu.gmall.publisher.beans.InteractionReviewUser;
import com.atguigu.gmall.publisher.beans.TrafficUvCt;
import com.atguigu.gmall.publisher.service.InteractionReviewService;
import com.atguigu.gmall.publisher.utils.DateFormatUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;

@RestController
public class InteractionReviewController {
        @Autowired
        private InteractionReviewService interactionReviewService;
        @RequestMapping("/totaluser")
        public String selectTotalUser(@RequestParam(value = "date", defaultValue = "0") Integer date,
                                      @RequestParam(value = "limit",defaultValue = "10") Integer limit){
            if(date == 0){
                date = DateFormatUtil.now();
            }
            List ciList = new ArrayList();
            List uvList = new ArrayList();
            List<InteractionReviewUser> ciUserList = interactionReviewService.selectTotalUser(date, limit);
            for (InteractionReviewUser interactionReviewUser : ciUserList) {
                ciList.add(interactionReviewUser.getCourseName());
                uvList.add(interactionReviewUser.getUser());
            }
            String json = "{\"status\": 0,\"data\": " +
                    "{\"categories\": [\""+ StringUtils.join(ciList,"\",\"") +"\"]," +
                    "\"series\": [{\"name\": \"课程\"," +
                    "\"data\": ["+StringUtils.join(uvList,",")+"]}]}}";
            return json;
        }

}
